package com.xudd.third.websocket;

import com.xudd.third.service.SimpleService;
import com.xudd.third.service.SimpleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;

import javax.annotation.Resource;
import java.io.IOException;
import java.text.MessageFormat;

public class SimpleWebSocketHandler extends TextWebSocketHandler {

	private final Logger logger = LoggerFactory.getLogger(getClass());

	@Resource
	private SimpleService sampleService;

	@Override
	protected void handleTextMessage(WebSocketSession session, TextMessage message) throws IOException {


		String simpleMessage = sampleService.simple(message.getPayload());
		logger.debug(MessageFormat.format("simg message\"{0}\"",simpleMessage));
		session.sendMessage(new TextMessage(simpleMessage));

	}



}
